package com.fanketly.funacg2.ui.components

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.MusicNote
import androidx.compose.material.icons.filled.MusicOff
import androidx.compose.material.icons.filled.Pause
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.PlaylistPlay
import androidx.compose.material.icons.filled.Repeat
import androidx.compose.material.icons.filled.RepeatOne
import androidx.compose.material.icons.filled.Shuffle
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector

@Composable
fun PlayModelIconButton(
    mode: Int,
    modifier: Modifier = Modifier,
    iconMaxSize: Float = 0.7f,
    tint: Color = Color.Gray,
    onClick: () -> Unit,
) {
    androidx.compose.material3.IconButton(
        modifier = modifier, onClick = onClick
    ) {
        ControllerIcon(//播放模式
            imageVector = when (mode) {
                100 -> Icons.Filled.Repeat
                200 -> Icons.Filled.RepeatOne
                else -> Icons.Filled.Shuffle
            },
            modifier = Modifier.fillMaxSize(iconMaxSize),
            tint = tint
        )
    }
}

@Composable
fun PlayOrPauseIconButton(
    isPlaying: Boolean,
    modifier: Modifier = Modifier,
    tint: Color = MaterialTheme.colorScheme.primary,
    onClick: () -> Unit,
) {
    androidx.compose.material3.IconButton(
        modifier = modifier,
        onClick = onClick//暂停或重新播放
    ) {
        ControllerIcon(
            if (isPlaying) Icons.Filled.Pause else Icons.Filled.PlayArrow, tint = tint
        )
    }
}


@Composable
fun PlayingIconButton(isPlaying: Boolean, modifier: Modifier = Modifier, onClick: () -> Unit) {
    androidx.compose.material3.IconButton(
        modifier = modifier,
        onClick = { if (isPlaying) onClick() }  //暂停或重新播放
    ) {
        ControllerIcon(
            if (isPlaying) Icons.Filled.MusicNote else Icons.Filled.MusicOff,
            tint = if (isPlaying) MaterialTheme.colorScheme.primary else Color.Gray
        )
    }
}

@Composable
fun BackIconButton(onBackClick: () -> Unit) {
    androidx.compose.material3.IconButton(
        onClick = onBackClick
    ) {
        androidx.compose.material3.Icon(Icons.Default.ArrowBack, null)
    }
}

@Composable
fun PlayListIconButton(
    modifier: Modifier = Modifier,
    tint: Color = Color.Gray,
    toPlayList: () -> Unit,
) {
    androidx.compose.material3.IconButton(//播放列表
        modifier = modifier, onClick = toPlayList
    ) {
        ControllerIcon(
            imageVector = Icons.Filled.PlaylistPlay,
            modifier = Modifier.fillMaxSize(0.7f),
            tint = tint
        )
    }
}

@Composable
fun ControllerIcon(
    imageVector: ImageVector,
    modifier: Modifier = Modifier,
    tint: Color = MaterialTheme.colorScheme.primary,
) {
    androidx.compose.material3.Icon(
        imageVector = imageVector,
        contentDescription = null,
        modifier = modifier.fillMaxSize(),
        tint = tint
    )
}

